package com.ezjie.login.core.helper;

import com.ezjie.baselib.application.MyApplication;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class AppDataBaseHelper extends SQLiteOpenHelper{
	public static final String USERINFO = "user_info";// 用户信息
	public static final String USER_IDX = "user_index";// 用户索引
	private static final String DB_Login_NAME = "login.db";
	private static final int DB_VERSION = 1;
	private static AppDataBaseHelper dbOpenHelper = null;
	public AppDataBaseHelper(Context context) {
		super(context, DB_Login_NAME, null, DB_VERSION);
		// TODO Auto-generated constructor stub
	}

	/**
	 * 得到数据库实例
	 * 
	 * @param context
	 * @return 数据库的SQLiteOpenHelper对象
	 */
	public static synchronized AppDataBaseHelper getInstance(Context context) {
		if (dbOpenHelper == null) {
			dbOpenHelper = new AppDataBaseHelper(MyApplication.myApplication);
			return dbOpenHelper;
		} else {
			return dbOpenHelper;
		}
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		/**
		 * 创建用户表
		 */
		db.execSQL("CREATE TABLE IF NOT EXISTS " + USERINFO + " (" + "_id" + " INTEGER PRIMARY KEY AUTOINCREMENT,"
				+ "uid" + " VARCHAR(30)," + "nick_name" + " VARCHAR(30)," + "mobile" + " VARCHAR(50)," + "email"
				+ " VARCHAR(50)," + "sex" + " VARCHAR(10)," + "head_url" + " VARCHAR(50)," + "login_key"
				+ " VARCHAR(50)," + "islogin" + " INTEGER," + "temp1" + " VARCHAR(50)," + "temp2" + " VARCHAR(50)"
				+ ");");
		db.execSQL("CREATE UNIQUE INDEX " + USER_IDX + " ON " + USERINFO + " (uid);");// 用户索引

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		
	}

}
///**
// * 创建用户表
// */
//db.execSQL("CREATE TABLE IF NOT EXISTS " + USERINFO + " (" + "_id" + " INTEGER PRIMARY KEY AUTOINCREMENT,"
//		+ "uid" + " VARCHAR(30)," + "nick_name" + " VARCHAR(30)," + "mobile" + " VARCHAR(50)," + "email"
//		+ " VARCHAR(50)," + "sex" + " VARCHAR(10)," + "head_url" + " VARCHAR(50)," + "login_key"
//		+ " VARCHAR(50)," + "islogin" + " INTEGER," + "temp1" + " VARCHAR(50)," + "temp2" + " VARCHAR(50)"
//		+ ");");
//db.execSQL("CREATE UNIQUE INDEX " + USER_IDX + " ON " + USERINFO + " (uid);");// 用户索引
